﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

//玩家管理
public class PlayerMgr:Singleton<PlayerMgr>
{

    public Dictionary<string, Player> PlayerDic
    {
        get
        {
            return m_playerDic;
        }
    }

    /// <summary>
    /// 新登录，临时写写后面要和数据库交互
    /// </summary>
    /// <param name="sessionId"></param>
    /// <param name="info"></param>
    public void NewPlayer(string sessionId, string info)
    {

        if (!m_playerDic.ContainsKey(sessionId))
        {

            Player player = new Player(sessionId,info);
            m_playerDic.Add(sessionId, player);
            player.ClientOnline();

            LOG.Log("收到客户端login 准备组织数据回客户端login完成");
            ProtoBuf.Login.RecLogin result = ProtoBuf.Login.RecLogin.CreateBuilder().SetUserName(sessionId)
                //.SetProp(0, 15)
                .SetLevel(1).Build();

            byte[] msg = result.ToByteArray();
            ByteBuffer buff = new ByteBuffer();
            //协议号
            buff.WriteUInt32(100);
            //协议体长度
            buff.WriteUInt32((UInt32)msg.Length);
            //协议体
            buff.WriteBytes(msg, false);
            //发送登录成功
            NetWorkMgr.singleton.SendMsg(sessionId, buff.ToBytes());
        }

    }

    private Dictionary<string, Player> m_playerDic = new Dictionary<string, Player>();

}
